package com.yihuier.yihuier.Mapper.MeetingManager;

import org.apache.ibatis.annotations.*;

@Mapper
public interface MeetingAttendMapper {
    @Insert("INSERT INTO bz_meeting_attend(attend_userid,attend_meetingid) VALUES(#{user_id},#{meeting_id});")
    int addOneRecordOfMeetingUserWithOutReason(@Param("user_id")int user_id, @Param("meeting_id")int meeting_id);

    @Insert("INSERT INTO bz_meeting_attend(attend_userid,attend_meetingid,attend_attendence,reason) VALUES(#{user_id},#{meeing_id},#{attendence},#{reason});")
    int addOneRecordOfMeetingUserWithReason(@Param("user_id")int user_id,@Param("meeting_id")int meeting_id,@Param("attendence")int status,@Param("reason")String reason);

    /**
     * 得到我参会的状态信息
     * */
    @Select("SELECT attend_attendence from bz_meeting_attend where attend_userid = #{user_id} AND attend_meetingid = #{meeting_id} LIMIT 1;")//只找一个，增加速度
    String selectAttend_attendence(@Param("user_id") int user_id,@Param("meeting_id") Long meeting_id);

    @Update("UPDATE bz_meeting_attend SET attend_attendence = 3 WHERE attend_meetingid = #{meeting_id} AND attend_attendence = 4")
    int updateAttendence(@Param("meeting_id") int meeting_id);


    @Update("UPDATE bz_meeting_attend SET attend_attendence = #{status},not_attend_reason = #{reason} WHERE attend_userid = #{user_id} AND attend_meetingid = #{meeting_id} ;")
    int updateOneRecordOfMeetingUserWithReason(@Param("user_id")int user_id,@Param("meeting_id")int meeting_id,@Param("status")int status,@Param("reason")String reason);


    @Select("SELECT COUNT(attend_userid) FROM bz_meeting_attend WHERE attend_userid = #{user_id} AND attend_meetingid = #{meeting_id};")
    int selectThisUserIfJoinMeeting(@Param("user_id")int user_id,@Param("meeting_id")int meeting_id);


    @Select("SELECT count(attend_meetingid) FROM bz_meeting_attend WHERE attend_userid = #{user_id};")
    int selectNumUserTotalAttendence(@Param("user_id") int user_id);

    @Select("SELECT count(attend_meetingid) FROM bz_meeting_attend WHERE attend_userid = #{user_id} AND attend_attendence = #{status};")
    int selectNumUserStatusAttendence(@Param("user_id") int user_id,@Param("status") int status);
}
